package com.venmo.view;

import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.render.Path;
import ohos.agp.utils.Color;
import ohos.agp.utils.RectFloat;

class TopArrowLocation implements ArrowLocation {

    @Override
    public void configureDraw(TooltipView view, Canvas canvas) {
        view.setTooltipPath(new Path());
        RectFloat rect = new RectFloat(view.getLeft(), view.getTop(),
                view.getRight(), view.getBottom());
        rect.top += (float) view.getArrowHeight();

        view.getTooltipPath().addRoundRect(rect, view.getCornerRadius(),
                view.getCornerRadius(), Path.Direction.CLOCK_WISE);

        float middle = ArrowAlignmentHelper.calculateArrowMidPoint(view, rect);

        view.getTooltipPath().moveTo(middle, 0f);
        float arrowDx = (float) view.getArrowWidth() / 2;
        view.getTooltipPath().lineTo(middle - arrowDx, rect.top);
        view.getTooltipPath().lineTo(middle + arrowDx, rect.top);
        view.getTooltipPath().close();
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        view.setPaint(paint);
        view.getTooltipPaint().setColor(new Color(view.getTooltipColor()));
    }
}
